package com.example.prom.ok.y2022.controller.taxbit;


import com.alibaba.fastjson.JSONObject;
import com.example.prom.ok.y2022.dto.taxbit.CreateAccountOwnerReqDTO;
import com.example.prom.ok.y2022.dto.taxbit.GetTaxBitUserRespDTO;
import com.example.prom.ok.y2022.dto.taxbit.TaxBitTokenRespDTO;
import com.example.prom.ok.y2022.dto.taxbit.TaxBitUserUpdateReqDTO;
import com.example.prom.ok.y2022.service.taxbit.TaxBitService;
import com.example.prom.utils.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/ok/y2022/taxbit")
@Slf4j
public class TaxbitController {

    @Autowired
    private TaxBitService taxBitService;

    @GetMapping("/{tenantId}/users/{userId}")
    public JSONObject getExistingTaxBitUser(@PathVariable("tenantId") String tenantId, @PathVariable("userId") String userId){
        return taxBitService.getExistingTaxBitUser(tenantId, userId);
    }

    @GetMapping("token/getAccountOwnerToken")
    public ResponseResult<TaxBitTokenRespDTO> getAccountOwnerToken(@RequestParam(value = "tenantId") String tenantId,
                                                                   @RequestParam(value = "tenantId") String accountOwnerId){
        return taxBitService.getAccountOwnerToken(tenantId, accountOwnerId);
    }

    @PutMapping("{tenantId}/users/{userId}")
    public ResponseResult<GetTaxBitUserRespDTO> updateTaxBitUser(@PathVariable("tenantId") String tenantId, @PathVariable("userId") String userId,
                                                                 @RequestBody TaxBitUserUpdateReqDTO taxBitUserUpdateReqDTO){
        return taxBitService.updateTaxBitUser(tenantId, userId, taxBitUserUpdateReqDTO);
    }

    @GetMapping("taxDocument/retrieve")
    public ResponseResult documentRetrieve(HttpServletRequest request){
        return taxBitService.taxDocumentRetrieve(request);
    }

    @PostMapping("taxDocument/submit")
    public ResponseResult documentSubmit(@RequestBody Map<String, Object> map){
        return taxBitService.documentSubmit(map);
    }

    @PostMapping("accountOwner/create")
    public ResponseResult createAccountOwner(String tenantId, @RequestBody CreateAccountOwnerReqDTO reqDTO){
        return taxBitService.createAccountOwner(tenantId, reqDTO);
    }

    @GetMapping("accountOwner/get")
    public ResponseResult getAccountOwner(String tenantId, String externalId){
        return taxBitService.getAccountOwner(tenantId, externalId);
    }

    @GetMapping("test/get")
    public String testGet(String id){
        return taxBitService.testGet(id);
    }

    @PostMapping("test/post")
    public CreateAccountOwnerReqDTO testPost(@RequestBody CreateAccountOwnerReqDTO reqDTO){
        return taxBitService.testPost(reqDTO);
    }

}
